﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;

public partial class User_PurchaseCardReg_CardEnter : System.Web.UI.Page
{
    AccountsCharge bllAccount = new AccountsCharge();
    WebUtility utility = new WebUtility();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void submit_Click(object sender, ImageClickEventArgs e)
    {
        string userType = Request.QueryString["UserType"].ToString();
        string regType = Request.QueryString["RegType"].ToString();
        string cardNO = WebUtility.replaceStr(this.realName.Text.Trim());
        string cardPwd = WebUtility.replaceStr(this.txt_password.Text.Trim());

        DataTable dtCardInfo = bllAccount.CheckCardInfo(cardNO, cardPwd);
        if (dtCardInfo.Rows.Count <= 0)
        {
            utility.AlertMsg("对不起您输入的卡号或密码错误，请得新输入！");
            return;
        }
        else
        {
            bool value = Convert.ToBoolean(dtCardInfo.Rows[0]["CPXX_IsUseable"].ToString());
            bool value2 = Convert.ToBoolean(dtCardInfo.Rows[0]["CPXX_ISActive"].ToString());
            bool value3 = Convert.ToBoolean(dtCardInfo.Rows[0]["CPXX_IsScraped"].ToString());
            if (value == false || value2 == false || value3 == false)
            {
                utility.AlertMsg("对不起，您输入的卡号不能使用！");
                return;
            }

            if (Convert.ToDateTime(dtCardInfo.Rows[0]["CPXX_ExpiredTime"].ToString()) < Convert.ToDateTime(DateTime.Now.ToString()))
            {
                utility.AlertMsg("对不起，您输入的卡号有效期已过！");
                return;
            }

            if (!string.IsNullOrEmpty(userType) && !string.IsNullOrEmpty(regType))
            {
                if (userType == "0" && regType == "1")
                {
                    Response.Redirect("CardPersonal.aspx?CardNo=" + cardNO + "&CardPwd=" + cardPwd + "");
                }
                else
                {
                    Response.Redirect("CardCompany.aspx?CardNo=" + cardNO + "&CardPwd=" + cardPwd + "");
                }
            }
        }
    }
}
